
package com.jf.cloud.delivery.controller.app;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.delivery.dto.TranscityDTO;
import com.jf.cloud.delivery.model.Transcity;
import com.jf.cloud.delivery.service.TranscityService;
import com.jf.cloud.delivery.vo.TranscityVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 运费项和运费城市关联信息
 *
 * @author zz
 * @date 2020-12-07 15:10:01
 */
@RestController("appTranscityController")
@RequestMapping("/transcity")
@Tag(name = "运费项和运费城市关联信息")
public class TranscityController {

    @Autowired
    private TranscityService transcityService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取运费项和运费城市关联信息列表" , description = "分页获取运费项和运费城市关联信息列表")
    public ServerResponseEntity<PageVO<TranscityVO>> page(@Valid PageDTO pageDTO) {
        PageVO<TranscityVO> transcityPage = transcityService.page(pageDTO);
        return ServerResponseEntity.success(transcityPage);
    }

    @GetMapping
    @Operation(summary = "获取运费项和运费城市关联信息" , description = "根据transcityId获取运费项和运费城市关联信息")
    public ServerResponseEntity<TranscityVO> getByTranscityId(@RequestParam Long transcityId) {
        return ServerResponseEntity.success(transcityService.getByTranscityId(transcityId));
    }

    @PostMapping
    @Operation(summary = "保存运费项和运费城市关联信息" , description = "保存运费项和运费城市关联信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody TranscityDTO transcityDTO) {
        Transcity transcity = mapperFacade.map(transcityDTO, Transcity.class);
        transcity.setTranscityId(null);
        transcityService.save(transcity);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新运费项和运费城市关联信息" , description = "更新运费项和运费城市关联信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody TranscityDTO transcityDTO) {
        Transcity transcity = mapperFacade.map(transcityDTO, Transcity.class);
        transcityService.update(transcity);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除运费项和运费城市关联信息" , description = "根据运费项和运费城市关联信息id删除运费项和运费城市关联信息")
    public ServerResponseEntity<Void> delete(@RequestParam Long transcityId) {
        transcityService.deleteById(transcityId);
        return ServerResponseEntity.success();
    }
}
